/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
void tree(struct TreeNode* root1, int* ret, int* retSize)
{
    if (root1 == NULL)
    {
        return;
    }

    ret[(*retSize)++] = root1->val;
    tree(root1->left, ret, retSize);
    tree(root1->right, ret, retSize);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int* ret = malloc(sizeof(int) * 2000);
    *returnSize = 0;
    tree(root, ret, returnSize);
    return ret;
}